package com.caishi.lkx.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caishi.lkx.course.mapper.LiveMapper;
import com.caishi.lkx.course.model.LiveModel;
import com.caishi.lkx.course.service.ILiveService;
import com.caishi.lkx.user.mapper.KcLiveUserMapper;
import com.caishi.lkx.user.model.KcLiveUserModel;
import com.zzw.common.entity.IBaseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;


@Service
public class LiveServiceImpl implements ILiveService {

    @Resource
    private LiveMapper liveMapper;
    @Autowired
    private KcLiveUserMapper kcLiveUserMapper;

    @Override
    public IBaseMapper<LiveModel, String> getMapper() {
        return liveMapper;
    }


    @Override
    public IPage<LiveModel> liveByColumnIdPage(Page<LiveModel> page, Map<String, Object> param) {
        return liveMapper.liveByColumnIdPage(page, param);
    }
    @Override
    public IPage<LiveModel> list(Page<LiveModel> page,Long categoryId) {
        return liveMapper.list(page,categoryId);
    }
    @Override
    public IPage<LiveModel> list1(Page<LiveModel> page, Map<String, Object> param) {
        return liveMapper.list1(page,param);
    }
    @Override
    public LiveModel getDetail(String id) {
        return liveMapper.getDetail(id);
    }

    @Override
    public int insertLiveUser(String userId, String liveId) {

        KcLiveUserModel build = KcLiveUserModel.builder()
                .userId(userId)
                .liveId(liveId)
                .build();
        int insert = kcLiveUserMapper.insert(build);
        return insert;
    }

    @Override
    public KcLiveUserModel getLiveUser(String userId, String liveId) {
        QueryWrapper<KcLiveUserModel> kcLiveUserModelQueryWrapper = new QueryWrapper<>();
        kcLiveUserModelQueryWrapper.eq("user_id",userId)
                        .eq("live_id",liveId);
        KcLiveUserModel kcLiveUserModel = kcLiveUserMapper.selectOne(kcLiveUserModelQueryWrapper);
        return kcLiveUserModel;
    }




}
